/** 
 * FileName:     Product.java 
 * @Description: TODO(用一句话描述该文件做什么) 
 * All rights Reserved, Designed By hnkeystone 
 * Copyright:    Copyright(C) 2010-2011 
 * Company       坚磐科技 
 * @author:    冯辉 
 * @version    V1.0  
 * Createdate:         2017-3-29 下午6:26:53 
 * 
 * Modification  History: 
 * Date         Author        Version        Discription 
 * ----------------------------------------------------------------------------------- 
 * 2017-3-29       hnkeystone.com          1.0             1.0 
 * Why & What is modified: <修改原因描述> 
 */
package com.fh.controller.product;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.fh.controller.base.BaseController;
import com.fh.entity.GoodsEntity;
import com.fh.entity.Page;
import com.fh.entity.system.User;
import com.fh.service.product.ProductService;
import com.fh.util.Const;
import com.fh.util.PageData;
import com.fh.util.SessionAreaUtil;

/**
 * @ClassName: Product
 * @Description:TODO(这里用一句话描述这个类的作用)
 * @author: 冯辉
 * @date: 2017-3-29 下午6:26:53
 * 
 */
@Controller
@RequestMapping(value = "/product")
public class Product extends BaseController {
	@Resource(name = "productService")
	private ProductService productService;
	
	/**
	 * 商品列表
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/productlist")
	public ModelAndView index() throws Exception {
		ModelAndView mv = this.getModelAndView();
		mv.setViewName("product/productlist");
		return mv;
	}

	/**
	 * 商品发布
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/productadd")
	public ModelAndView productadd() throws Exception {
		ModelAndView mv = this.getModelAndView();
		mv.setViewName("product/productadd");
		return mv;
	}

	/**
	 * 商品分类
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/categories")
	public ModelAndView categories() throws Exception {
		ModelAndView mv = this.getModelAndView();
		mv.setViewName("product/categories");
		return mv;
	}

	/**
	 * 商品列表
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/searchProductlist")
	public Object productlist() throws Exception {
		ModelAndView mv = this.getModelAndView();
		PageData pdParam = new PageData();
		pdParam = this.getPageData();
		String pageStr = pdParam.getString("page");
		if (pageStr != null) {
			int page = Integer.parseInt(pageStr);
			System.out.println(page);
		}
		User user = SessionAreaUtil.getSessionUser();
		Page pd = new Page();
		pd.setCurrentPage(1);
		pd.setShowCount(10);
		PageData pda = new PageData();
		pda.put("supplierID", user.getSupplierid());
		pd.setPd(pda);
		List<GoodsEntity> list = productService.findGoodsBySupplierId(pd);
		//把结果集和总条数返回
	    Map<String,Object> map=new HashMap<String,Object>();
	    map.put("total", pd.getTotalPage());
	    map.put("rows", list);
		return map;                     //rows键 存放每页记录 list 
	}

	/**
	 * 商品规格
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/specification")
	public ModelAndView specification() throws Exception {
		ModelAndView mv = this.getModelAndView();
		mv.setViewName("product/specification");
		return mv;
	}
}